<?php

if ( ! defined("IN_OP") )
{
    exit("You can't access this file directly...");
}
$gametype = intval(getvar("gametype"));
$chkGametype = chkGametype($gametype);
if ( $gametype == 0 )
{
    header("Location:op.php?op=admin&fp=srate1");
    exit();
}
if ( $chkGametype < 3 )
{
    header("Location:op.php?op=admin&fp=srate_3d&gametype={$gametype}");
    exit();
}
require_once( "class_3d/CheckMode_3d.php" );
$chk = new CheckMode_3d($curruser['acl'],5,$gametype);
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
$betname = judge_type($gametype);
if ( $gametype == 20 )
{
    $_5hFlag = true;
}
else
{
    $_5hFlag = false;
}
unset($chk);
$tblName = $g_gametype_3d[$gametype]['ch'];
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
require( "class_5h/SRate_5h.php" );
require( "class_5h/SRateTbl_5h.php" );
require( "class_5h/RateConfig_5h.php" );
$SRateTbl = new SRateTbl_5h($gametype);
$SRateTbl->sLottoId = 0;
$SRate = $SRateTbl;
$RateConfig = new RateConfig_5h($gametype);
if ( $_5hFlag )
{
    $subidArr5H8H = array(1,2,3,4,5);
}
else
{
    $subidArr5H8H = array(1,2,3,4,5,6,7,8);
}
$disk = isset($_POST['disk']) || isset($_GET['disk']) ? getvar("disk") : "a";
$playtype = getvar("playtype");
$alertMsgSyn = "";
$fieldArr = array("method"=>"5","gametype"=>$gametype,"round"=>"0","lotto_id"=>"0","betcontent"=>"","orate"=>"","nrate"=>"","pagename"=>"2","paperopen"=>$RateConfig->getPaperOpen());
$disk = $disk == "" ? "a" : $disk;
$playtype = isset($RateConfig->playtypeArr02[$playtype]) ? $playtype : "r1";
$bidstr = "";
if ( ! $RateConfig->checkDiskType($disk) )
{
    diemsg("{$tblName}不合法的盘类{$disk}");
}
$diskIdx = $RateConfig->disk_idx[$disk];
$bid = intval(getvar("bid"));
if ( in_array($playtype,$RateConfig->showAllBetArr02) )
{
    $bid = 0 < $bid ? $bid : $RateConfig->playGroupArr02[$playtype][0];
    if ( $_5hFlag && in_array($bid,array(15,16,17)) )
    {
        $bid = $RateConfig->playGroupArr02[$playtype][0];
    }
    if ( ! in_array($bid,$RateConfig->playGroupArr02[$playtype]) )
    {
        diemsg("{$tblName}玩法资料错误。");
    }
    $bidstr = "&bid=" . $bid;
    $tpl->set("bid",$bid);
}
else
{
    $bidstr = "";
    $bid = 0;
}
if ( 0 < $bid )
{
    $fieldsArr = array($bid);
}
else
{
    $fieldsArr = $RateConfig->playGroupArr02[$playtype];
}
$msg = "";
if ( in_array($playtype,$RateConfig->showAllSubArr02) )
{
    $subFlag = 1;
    $subid = intval(getvar("subid"));
    $subid = 0 < $subid ? $subid : 1;
    if ( ! isset($RateConfig->subArr[$subid]) )
    {
        diemsg("不合法的类别");
    }
}
else
{
    $subFlag = 0;
    $subid = 0;
}
$SRateTbl->subid = $subid;
if ( ispost() )
{
    $copyRateOK = intval(getvar("copyRateOK"));
    if ( isset($_POST['rateSynGametype']) )
    {
        if ( $_5hFlag )
        {
            exit("error");
        }
        else
        {
            $synStr = $tblName . "赔率为主, 八码赔率同步";
            $synGArr = array(20,21,23);
        }
        if ( $SRate->updateRateSynGametype() )
        {
            $fieldArr['betcontent'] = $synStr;
            $fieldArr['orate'] = "0";
            $fieldArr['nrate'] = "0";
            foreach ( $synGArr as $val )
            {
                $fieldArr['gametype'] = $val;
                setRateRecord($fieldArr);
            }
            $alertMsgSyn = "alert('{$synStr}');";
        }
        else
        {
            $fieldArr['betcontent'] = $synStr . "失败";
            $fieldArr['orate'] = "0";
            $fieldArr['nrate'] = "0";
            foreach ( $synGArr as $val )
            {
                $fieldArr['gametype'] = $val;
                setRateRecord($fieldArr);
            }
            $alertMsgSyn = "alert('{$synStr}');";
        }
    }
    else if ( $copyRateOK )
    {
        $errorI = $SRateTbl->copyRateBet(0);
        if ( 0 < $errorI )
        {
            $msg = $tblName . "&nbsp;::&nbsp;" . $RateConfig->playtypeArr02[$playtype] . "页面&nbsp;:: 赔率复制失败";
        }
        else
        {
            $msg = $tblName . "&nbsp;::&nbsp;" . $RateConfig->playtypeArr02[$playtype] . "页面&nbsp;:: 赔率复制完成";
            $fieldArr['betcontent'] = $_5hFlag ? "赔率复制(平码1-4及特码赔率同步)" : "赔率复制(球号1-8赔率同步)";
            $fieldArr['orate'] = 0;
            $fieldArr['nrate'] = 0;
            setRateRecord($fieldArr);
        }
    }
    else
    {
        $tempStr = "";
        $okI = 0;
        $subIdArr = array(0);
        foreach ( $fieldsArr as $val )
        {
            if ( in_array($val,$SRateTbl->betXYArr) )
            {
                $xyidArr = array(1,2);
            }
            else
            {
                $xyidArr = array(0);
            }
            if ( $subFlag )
            {
                $subidArr = array($subid);
            }
            else if ( in_array($val,$g_bet4subArr[$gametype]) )
            {
                $subidArr = $subidArr5H8H;
            }
            else
            {
                $subidArr = array(0);
            }
            if ( $gametype == 24 )
            {
                switch ( $val )
                {
                    case 0:
                        $subidArr = array($subid);
                        break;
                    case 3:
                    case 4:
                    case 5:
                        $subidArr = array(0);
                        break;
                    case 6:
                        $subidArr = array(1,2,3,4,5);
                        break;
                    default:
                        $subidArr = array(1,2,3,4,5,6,7,8,9,10);
                        break;
                }
            }
            $betTypeNumber = $RateConfig->getBetTypeNumber($val);
            foreach ( $subidArr as $subIdArrKey=> $subIdArrVal )
            {
                foreach ( $xyidArr as $xyidArrKey=> $xyidArrVal )
                {
                    $ratedataArr = array();
                    if ( $disk == "a" )
                    {
                        $rateBaseArr = $SRate->getRates("0",$xyidArrVal,1,$val,$subIdArrVal);
                    }
                    foreach ( $betTypeNumber as $key2=> $val2 )
                    {
                        $rateNum = str_pad($val2,2,"0",STR_PAD_LEFT);
                        $tempStr = "n_{$val}_{$subIdArrVal}_{$diskIdx}_{$rateNum}_{$xyidArrVal}";
                        $rateIdx = "r" . $rateNum;
                        if ( isset($_POST[$tempStr]) )
                        {
                            $floatval = floatval($_POST[$tempStr]);
                            $floatval = 0 < $floatval ? $floatval : "0";
                            $ratedataArr[$rateIdx] = $floatval;
                            if ( $disk == "a" && $floatval != $rateBaseArr[$rateIdx] )
                            {
                                $tempId = $val . "_" . $subIdArrVal;
                                $fieldArr['betcontent'] = "{$RateConfig->xyidTitle[$xyidArrVal]}[{$betname[$tempId]}]" . $RateConfig->getBetContent($val,$val2);
                                $fieldArr['orate'] = $rateBaseArr[$rateIdx];
                                $fieldArr['nrate'] = $floatval;
                                setRateRecord($fieldArr);
                            }
                            ++ $okI;
                        }
                        else
                        {
                            diemsg("更新{$tblName}失败","玩法资料与内容不齐全，无法更新({$tempStr})","op.php?op=admin&fp=srate_5h&disk={$disk}&playtype={$playtype}&gametype={$gametype}");
                        }
                    }
                    $SRate->updateRate("0",$xyidArrVal,$diskIdx,$val,$subIdArrVal,$ratedataArr);
                }
            }
        }
        if ( 0 < $okI )
        {
            $msg = $tblName . "&nbsp;::&nbsp;" . $RateConfig->playtypeArr02[$playtype] . "页面&nbsp;::&nbsp;" . $g_disk_name[$diskIdx] . "&nbsp;::&nbsp;" . "异动成&#21151;  (" . date("Y-m-d H:i:s") . ")";
        }
        else
        {
            $msg = "";
        }
    }
}
$SRateTbl->reloadUrl = "op.php?op=admin&fp=srate_5h&disk={$disk}&playtype={$playtype}{$bidstr}&gametype={$gametype}&subid={$subid}";
$SRateTbl->subURL = "op.php?op=admin&fp=srate_5h&disk={$disk}&playtype={$playtype}{$bidstr}&gametype={$gametype}&subid={$subid}";
foreach ( $fieldsArr as $val )
{
    if ( in_array($val,$g_betXYArr[$gametype]) )
    {
        $xyidArr = array(1,2);
    }
    else
    {
        $xyidArr = array(0);
    }
    if ( in_array($val,$g_bet4subArr[$gametype]) )
    {
        $subidArr = $subidArr5H8H;
    }
    else
    {
        $subidArr = array(0);
    }
    if ( $gametype == 24 )
    {
        switch ( $val )
        {
            case 0:
                $subidArr = array($subid);
                break;
            case 3:
            case 4:
            case 5:
                $subidArr = array(0);
                break;
            case 6:
                $subidArr = array(1,2,3,4,5);
                break;
            default:
                $subidArr = array(1,2,3,4,5,6,7,8,9,10);
                break;
        }
    }
    foreach ( $xyidArr as $xyidVal )
    {
        foreach ( $subidArr as $subidVal )
        {
            $rate_data = $SRate->getRates(0,$xyidVal,$diskIdx,$val,$subidVal);
            if ( $rate_data === false )
            {
                $SRate->addRates(0,$xyidVal,$diskIdx,$val,$subidVal,array());
                if ( $disk == "a" )
                {
                    $SRate->addRates(0,$xyidVal,2,$val,$subidVal,array());
                    $SRate->addRates(0,$xyidVal,3,$val,$subidVal,array());
                    $SRate->addRates(0,$xyidVal,4,$val,$subidVal,array());
                }
            }
        }
    }
}
$jslink = "<script>";
$jslink .= "$(function(){ $().chgIptClr();   ";
$jslink .= "});";
$jslink .= "</script>";
$jslink .= "<script src=\"js_3d/showRateRecord.js\"></script>";
$jslink .= "<script src=\"js_3d/js3d.js\"></script>";
$jslink .= "<script src=\"js_3d/jsRate5h.js\"></script>";
$ui->set("jslink",$jslink);
$ui->header();
$disks = "<select onchange=\"location.replace('op.php?op=admin&fp=srate_5h&playtype=" . $playtype . $bidstr . "&subid={$subid}&gametype={$gametype}&disk='+this.value)\">";
foreach ( $g_disk_name as $key=> $val )
{
    $chkDisk = $g_disk_code[$key];
    $selectStr = $disk == $chkDisk ? " selected" : "";
    $disks .= "<option value='{$chkDisk}' {$selectStr}>{$val}</option>";
}
$disks .= "</select>";
$gameTypeStr = getOptionList($gametype,"op.php?op=admin&fp=srate_5h&playtype=" . $playtype . $bidstr . "&disk={$disk}");
if ( ! $_5hFlag && $gametype != 24 )
{
    $gameTypeStr .= "&nbsp;<input type='submit' value='八码同步' id='rateSynGametype' class=\"nobtnclass colorBtnGray\" />";
    $synStr = "【{$tblName}】 赔率为主, 同步其他八码彩类赔率";
    $acURL = "op.php?op=admin&fp=srate_5h&disk={$disk}&playtype={$playtype}{$bidstr}&gametype={$gametype}";
    echo "<script>";
    echo $alertMsgSyn;
    echo "$(function(){\r\n    $(\"input#rateSynGametype\").click(function(){\r\n      if(confirm(\"确定要以 " . $synStr . "(包含所有盘类)?\")){\r\n        $.post(\"" . $acURL . "\", {rateSynGametype:\"1\"},function() {\r\n          alert(\"同步完成!请切换至其他彩类复查是否同步\");\r\n        });\r\n      }\r\n      return true;\r\n    });\r\n  });\r\n  </script>\r\n  ";
}
include( "admin_menu_3d.php" );
$playtypeArr = $RateConfig->playtypeArr02;
$playMenu = "";
$playMenuArr = array();
foreach ( $playtypeArr as $key=> $val )
{
    if ( in_array($key,$RateConfig->showAllBetArr02) )
    {
        $bidStrTemp = "&bid=" . $RateConfig->playGroupArr02[$key][0];
    }
    else
    {
        $bidStrTemp = "";
    }
    if ( $key == $playtype )
    {
        $playMenuArr[] = "<span class=\"cBig\">{$val}</span>";
    }
    else
    {
        $playMenuArr[] = "<a href=\"op.php?op=admin&fp=srate_5h&gametype={$gametype}&playtype={$key}{$bidStrTemp}\">{$val}</a>";
    }
}
$playMenu = implode("&nbsp;|&nbsp;",$playMenuArr);
$playMenu2 = "<input type=\"button\" value=\"赔率异动纪录\" class=\"nobtnclass colorBtnGray\" onclick=\"javascript:showRateRecordPageBase({$gametype},'2');\"  />";
$g_5number_3dStrTitle = $_5hFlag ? "【４＋１码】" : "【八码】";
echo "<div id=\"divRateRecord\"></div>";
echo "<style> thead, th{font-size:0.9em;} </style>";
echo "<div class='bgImg_{$gametype}' style='width:753px;padding:5px;'><span style='float:left'>{$tblName}&nbsp;&nbsp;&nbsp;{$playtypeArr[$playtype]} &nbsp;&nbsp;&nbsp;{$g_5number_3dStrTitle}基本赔率设定 ---  {$disks}</span><span style='float:right'>{$gameTypeStr} {$playMenu2}</span><br /><br />{$playMenu}</div>";
echo $msg == "" ? "" : "<div class='msgBox-yellow'>{$msg}</div>";
echo "<form name='frmSrate' action='op.php?op=admin&fp=srate_5h&disk={$disk}&playtype={$playtype}{$bidstr}&gametype={$gametype}&subid={$subid}' method='post' style='margin-top:0'>";
echo $SRateTbl->show_srateTbl($playtype,$disk,$subid,$bid);
echo "</form>";
echo "<span> ※ 快调时, <font style='background-color:#FF9291'>浅红底</font>表示赔率小於 1 </span>";
echo "<br /><span> ※ [<input type='button' class='colorBtnGray' value='- ' /><input type='button' class='colorBtnGray' value='+' />]按钮 每次异动量为<font style='background-color:#FF9291'>0.01</font>" . ( $_5hFlag ? ", 且XY盘同时异动" : "" ) . "，异动後请记得按[确定更改]钮</span>";
echo "<br /><span> ※ {$tblName}玩法，可设定赔率至小数点下第三位。</span>";
echo "<br /><span> ※ 赔率快速归零小技巧:增量栏位输入负极大值(例 -999999)，按「全部」钮即可。</span>";
echo "</td></tr></table>";
$ui->footer();